package com.itheima.mobilesafe.ui;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.CheckBox;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.example.gggg.R;

public class SettingItemView extends RelativeLayout {

	public CheckBox cb_status;
	public TextView tv_desc;
	public TextView tv_title;

	private String title;
	private String desc_on;
	private String desc_off;

	public SettingItemView(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		iniView(context);
	}

	private void iniView(Context context) {
		View.inflate(context, R.layout.setting_item_view, this);
		tv_title=(TextView) findViewById(R.id.tv_title);
		cb_status = (CheckBox) this.findViewById(R.id.cb_status);
		tv_desc = (TextView) this.findViewById(R.id.tv_desc);

	}

	public SettingItemView(Context context, AttributeSet attrs) {
		super(context, attrs);
		iniView(context);
		title = attrs.getAttributeValue(
						"http://schemas.android.com/apk/res/com.example.gggg",
						"title1");

		desc_on = attrs.getAttributeValue(
				"http://schemas.android.com/apk/res/com.example.gggg",
				"desc_on");

		desc_off = attrs.getAttributeValue(
				"http://schemas.android.com/apk/res/com.example.gggg",
				"desc_off");
	setDesc(desc_off);
		/*
		 * System.out.println(attrs.getAttributeValue(0));
		 * System.out.println(attrs.getAttributeValue(1));
		 * System.out.println(attrs.getAttributeValue(2));
		 * System.out.println(attrs.getAttributeValue(3));
		 * System.out.println(attrs.getAttributeValue(4));
		 * System.out.println(attrs.getAttributeValue(5));
		 */
	}

	public SettingItemView(Context context) {
		super(context);
		iniView(context);
		// TODO Auto-generated constructor stub
	}

	public boolean isChecked() {
		return cb_status.isChecked();
	}

	public void setChecked(boolean checked) {
		if (checked) {
			setDesc(desc_on);
		} else {
			setDesc(desc_off);
		}
		cb_status.setChecked(checked);
	}

	public void setDesc(String text) {
		tv_desc.setText(text);
	}

}
